import tensorflow as tf
import os
from common import show_picture

if __name__ == '__main__':
    os.environ["TF_CPP_MIN_LOG_LEVEL"] = '2'
    image_path = './lenna.png'

    # 读取图片数据
    image = tf.io.read_file(image_path)
    image = tf.image.decode_png(image)

    show_picture(image, 'lenna.png')

    # 转换图片数据类型为浮点数
    float_image = tf.image.convert_image_dtype(image, tf.float32)

    resized_image = tf.image.resize(float_image, size=(256, 256))
    show_picture(resized_image, 'resized_image_lenna.png')

    # 转换图片数据类型为整数
    resized_image = tf.image.convert_image_dtype(resized_image, tf.uint8)
    # 将图像数据进行编码
    resized_image = tf.image.encode_png(resized_image)
    # 将编码后的数据保存到文件
    tf.io.write_file('resized_image_lenna.png', resized_image)
